package ruifeng.zcj.happymahjony.util;

import android.content.Context;

import org.json.JSONArray;

/**
 * Created by Administrator on 2016/9/21 0021.
 */
public class CacheUtil {
    public static CacheUtil sCacheUtil;
    private static ACache mCache;
    private Context activity;

    public CacheUtil(Context activity) {
        this.activity = activity;
        mCache = ACache.get(activity);
    }

    public CacheUtil() {

    }

    public static CacheUtil getCacheUtil() {
        return sCacheUtil;
    }

    public static void setCacheClient(CacheUtil c) {
        sCacheUtil = c;
    }

    /***
     * 缓存一个jsonArray
     ***/
    public static void cacheJsonArray(JSONArray jsonArray, String jsonName) {
        mCache.put(jsonName, jsonArray);
    }

    /***
     * 读取一个jsonArray
     ***/
    public static JSONArray readJsonArray(String jsonName) {
        JSONArray testJsonArray = mCache.getAsJSONArray(jsonName);
        if (testJsonArray == null) {
            return null;
        }
        return testJsonArray;
    }

    /**
     * 缓存一个string
     **/
    public static void cacheString(String name, String json) {
        mCache.put(name, json);
    }

    /**
     * 读取一个json
     **/
    public static String readString(String name) {
        return mCache.getAsString(name);
    }

    /**
     * 移除对应的String
     **/
    public static void clear(String name) {
        mCache.remove(name);
    }

    /**
     * 缓存一个对象
     **/
    public static void cacheSerializable(String name, Base json) {
        mCache.put(name, json);
    }

    /**
     * 读取一个SerializableObject
     **/
    public static Object readObject(String name) {
        return mCache.getAsObject(name);
    }
}
